//
//  SettingCell.swift
//  Youtube2
//
//  Created by 劢克科技 on 2019/6/12.
//  Copyright © 2019 meckey. All rights reserved.
//

import UIKit

class SettingCell: UICollectionViewCell {
    
    override var isHighlighted: Bool {
        didSet {
            self.backgroundColor = self.isHighlighted ? UIColor.gray : UIColor.white
            self.icon.tintColor = self.isHighlighted ? UIColor.white : UIColor.gray
            self.title.textColor = self.isHighlighted ? UIColor.white : UIColor.gray
        }
    }
    
    override init(frame: CGRect) {
        super.init(frame: frame)
                
        contentView.addSubview(title)
        contentView.addSubview(icon)
        
        title.leftAnchor.constraint(equalTo: icon.rightAnchor, constant: 10).isActive = true
        title.centerYAnchor.constraint(equalTo: contentView.centerYAnchor).isActive = true
        
        icon.widthAnchor.constraint(equalToConstant: 30).isActive = true
        icon.heightAnchor.constraint(equalToConstant: 30).isActive = true
        icon.leftAnchor.constraint(equalTo: contentView.leftAnchor, constant: 16).isActive = true
        icon.centerYAnchor.constraint(equalTo: contentView.centerYAnchor).isActive = true
        
    }
    
    required init?(coder aDecoder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
    
    lazy var title: UILabel = {
        let label = UILabel()
        label.font = UIFont.systemFont(ofSize: 13)
        label.textColor = UIColor.gray
        label.text = "Hello World"
        label.translatesAutoresizingMaskIntoConstraints = false
        return label
    }()
    
    lazy var icon: UIImageView = {
        let icon = UIImageView()
        icon.image = #imageLiteral(resourceName: "fire").withRenderingMode(UIImage.RenderingMode.alwaysTemplate)
        icon.tintColor = UIColor.gray
        icon.translatesAutoresizingMaskIntoConstraints = false
        return icon
    }()
}
